package algorithms.evictpolicy;

public class FIFOEvictPolicy<K> implements EvictPolicy<K>{

    private Queue<K> queue;

    public FIFOEvictPolicy(int size) {
        this.queue = new Queue<>(size);
    }


    public boolean onPut(K k, boolean exits, EvictionHandler<K> handler) {
        if (exits) {
            return true;
        }
        K evict = queue.push(k);
        if (evict != null) {
            handler.onEvict(evict);
        }
        return true;
    }

    @Override
    public void onGet(K k, boolean hit) {
       //do nothing
    }

    @Override
    public void onRemove(K k, boolean exists) {
        if (!exists) return;
        queue.remove(k);
    }
}
